package implementations;

import interfaces.Edge;
import interfaces.Vertex;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * @author Kai Bielenberg
 * @author Oliver Behnke
 *
 * @param <E>
 * @param <V>
 */
public class UndirectedEdge<E, V> extends AbstractEdge<E, V> {


	private UndirectedEdge(String name, Vertex<V> start, Vertex<V> end, E element) {
		this.start = start;
		this.end = end;
		this.element = element;
		this.name = name;
	}

//	static <E, V> UndirectedEdge<E, V> valueOf(String name, Vertex<V> v1, Vertex<V> v2) {
//		return new UndirectedEdge<E, V>(name, v1, v2);
//	}

	static <E, V> AbstractEdge<E, V> valueOf(String name, Vertex<V> v1,
			Vertex<V> v2, E element) {
		return new UndirectedEdge<E, V>(name, v1, v2, element);
	}

	@Override
	public boolean areParallel(Edge<E, V> e) {
		recordAccess();
		return e.vertices().containsAll(this.vertices())
				&& this.vertices().containsAll(e.vertices());
	}


	@Override
	public boolean isDirected() {
		recordAccess();
		return false;
	}


	@Override
	public boolean equals(Object o) {
		recordAccess();
		//Quick Check for same Object
		if (o == this) return true;
		//Type Check
		if (!(o instanceof Edge<?,?>)) return false;
		Edge<?,?> edge= (Edge<?,?>) o;
		//Check of the Arguments
		return this.name.equals(edge.name())  && this.vertices().containsAll(edge.vertices()) && edge.vertices().containsAll(this.vertices());
	}



}
